// 部门相关类型
export interface Department {
  id: number
  name: string
  code: string
  description?: string
  parentId?: number
  level: number
  sort: number
  status: 'active' | 'inactive'
  createTime: string
  updateTime: string
  children?: Department[]
}

export interface DepartmentForm {
  name: string
  code: string
  description?: string
  parentId?: number
  sort: number
  status: 'active' | 'inactive'
}

// 承包商相关类型
export interface Contractor {
  id: number
  name: string
  code: string
  contactPerson: string
  contactPhone: string
  contactEmail: string
  address?: string
  qualificationLevel: 'A' | 'B' | 'C' // 资质等级
  businessScope: string[]
  status: 'active' | 'inactive'
  createTime: string
  updateTime: string
}

export interface ContractorForm {
  name: string
  code: string
  contactPerson: string
  contactPhone: string
  contactEmail: string
  address?: string
  qualificationLevel: 'A' | 'B' | 'C'
  businessScope: string[]
  status: 'active' | 'inactive'
}

// 用户相关类型
export interface User {
  id: number
  username: string
  nickname: string
  email: string
  phone: string
  avatar?: string
  status?: 'active' | 'inactive'
  roles: string[]
  departmentId?: number
  departmentName?: string
  contractorId?: number
  contractorName?: string
  employeeNumber?: string
  position?: string
  createTime?: string
  updateTime?: string
}

export interface UserForm {
  username: string
  nickname: string
  email: string
  phone: string
  password?: string
  status: 'active' | 'inactive'
  roles: string[]
  departmentId?: number
  contractorId?: number
  employeeNumber?: string
  position?: string
}

// 角色相关类型
export interface Role {
  id: number
  name: string
  code: string
  description: string
  type: 'system' | 'business' // 系统角色或业务角色
  level?: number // 用于权威人员和批准人的等级
  permissions: string[]
  createTime: string
  updateTime: string
}

// 文件管理相关类型
export interface FileItem {
  id: number
  name: string
  type: 'file' | 'folder'
  size?: number // 文件大小（字节）
  extension?: string // 文件扩展名
  path: string // 文件路径
  parentId?: number // 父文件夹ID
  uploadTime: string
  uploader: string
  uploaderId: number
  description?: string
  tags: string[] // 文件标签
  category: 'document' | 'image' | 'video' | 'audio' | 'archive' | 'other' // 文件分类
  isPublic: boolean // 是否公开
  downloadCount: number // 下载次数
  updateTime: string
  // 文件夹权限管理
  folderType?: 'public' | 'private' // 文件夹类型：公开或私有
  ownerId?: number // 文件夹所有者ID（私有文件夹）
  canUpload?: boolean // 是否允许上传
  canDownload?: boolean // 是否允许下载
  canManage?: boolean // 是否允许管理（重命名、删除等）
}

export interface FileForm {
  name: string
  type: 'file' | 'folder'
  parentId?: number
  description?: string
  tags: string[]
  category: 'document' | 'image' | 'video' | 'audio' | 'archive' | 'other'
  isPublic: boolean
  // 文件夹权限管理
  folderType?: 'public' | 'private' // 文件夹类型：公开或私有
  ownerId?: number // 文件夹所有者ID（私有文件夹）
}

// 菜单相关类型
export interface Menu {
  id: number
  name: string
  path: string
  icon?: string
  component?: string
  parentId?: number
  sort: number
  visible: boolean
  children?: Menu[]
}

// 权限相关类型
export interface Permission {
  id: number
  name: string
  code: string
  type: 'menu' | 'button'
  parentId?: number
  path?: string
  method?: string
}

// API响应类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface PageData<T = any> {
  list: T[]
  total: number
  page: number
  size: number
}

// 分页参数
export interface PageParams {
  page: number
  size: number
  keyword?: string
}

// 登录相关类型
export interface LoginForm {
  username: string
  password: string
  captcha?: string
}

export interface LoginResponse {
  token: string
  user: User
  permissions: string[]
  menus: Menu[]
}

// JSA模板相关类型
export interface JSAWorkStep {
  id: number
  stepName: string
  sequence: number
  responsiblePersons?: string[] // 责任人ID数组
}

export interface JSAHazard {
  id: number
  hazardName: string
  tempId?: string
}

export interface JSAControlMeasure {
  id: number
  measureName: string
}

export interface JSAWorkStepHazard {
  id: number
  workStepId: number
  hazardId: number
  workStep: JSAWorkStep
  hazard: JSAHazard
}

export interface JSAHazardControl {
  id: number
  hazardId: number
  controlMeasureId: number
  hazard: JSAHazard
  controlMeasure: JSAControlMeasure
}

export interface JSATemplate {
  id: number
  name: string
  jobType: string
  workSteps: JSAWorkStep[]
  hazards: JSAHazard[]
  controlMeasures: JSAControlMeasure[]
  workStepHazards: JSAWorkStepHazard[]
  hazardControls: JSAHazardControl[]
  isActive: boolean
  createTime: string
  updateTime: string
  creator: string
}

export interface JSATemplateForm {
  name: string
  jobType: string
  workSteps: Omit<JSAWorkStep, 'id'>[]
  hazards: Omit<JSAHazard, 'id'>[]
  controlMeasures: Omit<JSAControlMeasure, 'id'>[]
  workStepHazards: { workStepSequence: number; hazardName: string; tempId?: string }[]
  hazardControls: { hazardName: string; controlMeasureName: string }[]
}
